var a = getApp();
Page({
  data: {
    // 改前
    // showFlag: !1,
    // 改后
    showFlag: !0,
    jjboor: true,
    type: 0,
    yaoqing: 0,
    detailList: {
      creater: {
        doctorId: 1,
        userIcon: '/assets/images/head.png',
        teamName: '老三',
        teamDesc: '专治胃病',
        patientCount: 10,
        doctorCount: 9,
        unreadNewsQuantity: 123,
        serviceItems: [1, 2, 3],
        moneybag: {
          money: 100000
        },
        saidCount: 5
      }
    }
  },
  jujue() {
    this.setData({
      jjboor: false
    })
  },
  previewImage: function(a) {
    console.log(a), this.data.showFlag = !0;
    var t = [a.target.dataset.url];
    wx.previewImage({
      urls: t
    });
  },
  goTointro: function(t) {
    var that = this
    var zid = that.data.zid
    console.log(a), wx.setStorageSync("doctorId", t.target.dataset.id), wx.navigateTo({
      url: "/hyb_yl/backstageTeam/pages/doctorIntro/doctorIntro?type=1" + '&zid=' + zid
    });
  },
  setting: function() {
    var that = this;
    var t_id = that.data.t_id
    var zid = that.data.zid
    var type = that.data.type
    if (type == 1) {
      wx.showActionSheet({
        itemList: ["退出团队"],
        itemColor: "#ff4c4c",
        success: function(e) {
          console.log(e.tapIndex), wx.request({
            url: a.globalData.dic + "doctor/team/quit/" + t.data.token + "/" + t.data.teamId,
            success: function(a) {
              if (console.log(a.data.code), 200 == a.data.code) {
                if (1 == t.data.groupFlag) return void wx.navigateBack({
                  delta: 3
                });
                wx.navigateBack({
                  delta: 2
                });
              }
            }
          });
        },
        fail: function(a) {
          console.log(a.errMsg);
        }
      });
    } else {
      wx.navigateTo({
        url: "/hyb_yl/backstageTeam/pages/createTeam/createTeam?t_id=" + t_id + '&zid=' + zid + '&type=1'
      })
    }

  },
  onLoad: function(t) {
    var e = this;
    console.log(t)
    var teampic = t.teampic
    if (t.yao_id) {
      var yao_id = t.yao_id
      e.setData({
        yao_id: yao_id
      })
    }
    if (t.yaoqing) {
      var yaoqing = t.yaoqing
      var t_id = t.t_id
      console.log(t_id, yaoqing)
      e.setData({
        yaoqing: yaoqing,
        t_id: t_id
      })
      this.getMyiftongyi()
    }
    this.setData({
      teampic: t.teampic,
      t_id: t.t_id,
      zid: t.zid,
      teamtext: t.teamtext,
      teamname: t.teamname,
      z_thumbs: t.z_thumbs,
      z_name: t.z_name,
    })

  },
  onReady: function() {},
  onShow: function() {
    // var t = this;
    // this.data.showFlag 
    // || (wx.showLoading({
    //     title: "加载中...",
    //     mask: !0
    // })
    // , 
    // wx.request({
    //     url: a.globalData.dic + "doctor/team/detail/" + t.data.token + "/" + t.data.teamId,
    //     success: function(a) {
    //         if (console.log(a), 200 == a.data.code) {
    //             wx.hideLoading();
    //             var e = a.data.data.createTime.split(" ");
    //             a.data.data.createTime = e[0], t.setData({
    //                 detailList: a.data.data,
    //                 img: a.data.data.teamHeaderUrl
    //             }), a.data.data.teamDesc.length > 65 ? t.setData({
    //                 teamDescFlag: !0
    //             }) : t.setData({
    //                 teamDescFlag: !1
    //             });
    //         }
    //     }
    // })), this.data.showFlag = !1;
  },
  tapFlag: function() {
    console.log(111), this.setData({
      teamDescFlag: !this.data.teamDescFlag
    }), this.data.teamDescFlag ? this.setData({
      downFlag: !1
    }) : this.setData({
      downFlag: !0
    });
  },
  serve: function(a) {
    var that = this
    var t_id = that.data.t_id
    wx.navigateTo({
      url: "/hyb_yl/doctor/pages/familydoctor/category/category?t_id=" + t_id
    });
  },
  list: function(e) {
    var that = this
    var teampic = that.data.teampic
    var t_id = that.data.t_id
    var zid = that.data.zid
    var teamtext = that.data.teamtext
    var teamname = that.data.teamname
    var z_name = that.data.z_name
    var z_thumbs = that.data.z_thumbs
    if (that.data.yaoqing == 1) {
      wx.navigateTo({
        url: "/hyb_yl/backstageTeam/pages/list/list?teampic=" + teampic + '&t_id=' + t_id + '&zid=' + zid + '&teamtext=' + teamtext + '&teamname=' + teamname + '&z_name=' + z_name + '&z_thumbs=' + z_thumbs + '&yaoqing=' + that.data.yaoqing
      });
    } else {
      wx.navigateTo({
        url: "/hyb_yl/backstageTeam/pages/list/list?teampic=" + teampic + '&t_id=' + t_id + '&zid=' + zid + '&teamtext=' + teamtext + '&teamname=' + teamname + '&z_name=' + z_name + '&z_thumbs=' + z_thumbs
      });
    }
  },
  clickname: function(a) {
    var t = this;
    wx.navigateTo({
      url: "/hyb_yl/backstageOther/pages/teamDetails1/teamDetails1?teamName=" + t.data.detailList.teamName
    });
  },
  clicknameText: function(a) {
    wx.navigateTo({
      url: "/hyb_yl/backstageOther/pages/teamDetails2/teamDetails2?briefIntroduce=" + this.data.detailList.teamDesc
    });
  },
  member: function(a) {
    wx.navigateTo({
      url: "/hyb_yl/backstageTeam/pages/teamDetails3/teamDetails3"
    });
  },
  Wimg: function(t) {
    var e = this,
      o = (wx.getStorageSync("log"), wx.getStorageSync("teamId") || "");
    wx.chooseImage({
      count: 1,
      sizeType: ["orignal", "compressed"],
      sourceType: ["album", "camera"],
      success: function(t) {
        console.log(t.tempFilePaths[0]), e.setData({
          img: t.tempFilePaths[0]
        });
        var i = wx.getStorageSync("log") || "";
        wx.uploadFile({
          url: a.globalData.dic + "doctor/team/update/" + i,
          filePath: t.tempFilePaths[0],
          name: "file",
          formData: {
            teamId: o,
            flag: 1
          },
          method: "POST",
          header: {
            "Content-Type": "multipart/form-data"
          },
          success: function(t) {
            console.log(t), wx.request({
              url: a.globalData.dic + "doctor/team/detail/" + e.data.token + "/" + e.data.teamId,
              success: function(a) {
                if (console.log(a), 200 == a.data.code) {
                  wx.hideLoading();
                  var t = a.data.data.createTime.split(" ");
                  a.data.data.createTime = t[0], e.setData({
                    detailList: a.data.data,
                    img: a.data.data.teamHeaderUrl
                  }), console.log(e.data.detailList);
                }
              }
            });
          }
        });
      }
    });
  },
  navCode: function(e) {
    var that = this
    var t_id = that.data.t_id
    var z_thumbs = that.data.z_thumbs
    var z_name = that.data.z_name
    //生成二维码
    a.util.request({
      'url': 'entry/wxapp/Studio.teamerweima',
      data: {
        t_id: t_id,
      },
      success: function(res) {
        console.log(res)
        var tderweima = res.data.tderweima
        var info = JSON.stringify(res.data)
        // wx.navigateTo({
        //   url: '/hyb_yl/backstageLifes/pages/dialysis/dialysis?info= ' + info + '&weweima=' + weweima,
        // })
        wx.navigateTo({
          url: "/hyb_yl/backstageTeam/pages/teamDetails4/teamDetails4?info=" + info + '&tderweima=' + tderweima + '&z_name=' + z_name + '&z_thumbs=' + z_thumbs
        });
      },
    })



  },
  shanchu: function(t) {
    var e = this;
    wx.request({
      url: a.globalData.dic + "doctor/team/getTeamUnfinishedOrder",
      data: {
        teamId: e.data.teamId
      },
      success: function(t) {
        console.log(), t.data.data ? wx.showModal({
          title: "请先结束未完成咨询！",
          showCancel: !1,
          confirmColor: "#3b4ca9",
          confirmText: "取消",
          success: function(a) {
            a.confirm || a.cancel;
          }
        }) : wx.showModal({
          title: "提示",
          content: "您确认解散团队吗？",
          success: function(t) {
            t.confirm ? wx.request({
              url: a.globalData.dic + "doctor/team/break",
              data: {
                token: e.data.token,
                teamId: e.data.teamId
              },
              method: "POST",
              header: {
                "Content-Type": "application/x-www-form-urlencoded"
              },
              success: function(a) {
                if (console.log(a.data), 200 == a.data.code) {
                  if (1 == e.data.groupFlag) return void wx.navigateBack({
                    delta: 3
                  });
                  wx.navigateBack({
                    delta: 2
                  });
                }
              }
            }) : t.cancel && console.log("用户点击取消");
          }
        });
      }
    });
  },
  shanchu1: function(t) {
    var e = this;
    wx.showModal({
      title: "提示",
      content: "您确认退出团队吗？",
      success: function(t) {
        t.confirm ? wx.request({
          url: a.globalData.dic + "doctor/team/quit/" + e.data.token + "/" + e.data.teamId,
          success: function(a) {
            if (console.log(a.data.code), 200 == a.data.code) {
              if (1 == e.data.groupFlag) return void wx.navigateBack({
                delta: 3
              });
              wx.navigateBack({
                delta: 2
              });
            }
          }
        }) : t.cancel && console.log("用户点击取消");
      }
    });
  },
  invitation: function(a) {
    wx.navigateTo({
      url: "/hyb_yl/backstageOther/pages/teamDetails5/teamDetails5"
    });
  },
  entersubmit: function(e) {
    //确定同意或者拒绝
    var that = this
    var yao_type = e.detail.target.id
    var yao_id = that.data.yao_id
    var form_id = e.detail.formId
    var t_id = that.data.t_id
    a.util.request({
      'url': 'entry/wxapp/UserFormId',
      'data': {
        form_id: form_id,
        openid: wx.getStorageSync('openid')
      },
      success: function(res) {
        console.log(res)
        //执行操作
        a.util.request({
          'url': 'entry/wxapp/Yaoqing',
          'data': {
            yao_type: yao_type,
            yao_id: yao_id,
            t_id: t_id,
            op: 'entryyao'
          },
          success: function(res) {
            console.log(res)
            //执行操作
            if (res.data == 0) {
              if (yao_type == 1) {
                wx.showToast({
                  title: '同意成功',
                  icon: 'none',
                  duration: 2e3
                })
                that.setData({
                  type: 1
                })
              } else {
                wx.showToast({
                  title: '拒绝成功',
                  icon: 'none',
                  duration: 2e3
                })
              }

            } else {
              if (yao_type == 1) {
                wx.showToast({
                  title: '同意成功',
                  icon: 'none',
                  duration: 2e3
                })
                that.setData({
                  type: 1
                })
              } else {
                wx.showToast({
                  title: '拒绝成功',
                  icon: 'none',
                  duration: 2e3,
                  success: function() {
                    setTimeout(function() {
                      wx.reLaunch({
                        url: '/hyb_yl/tabBar/index/index',
                      })
                    }, 2000)
                  }
                })
              }
            }
          }
        })
      }
    })
  },
  // getMyiftongyi: function() {
  //   var that = this
  //   var t_id = that.data.t_id
  //   a.util.request({
  //     'url': 'entry/wxapp/Yaoqing',
  //     data: {
  //       t_id: t_id,
  //       openid: wx.getStorageSync('openid'),
  //       op: 'ifyq'
  //     },
  //     success: function(res) {
  //       console.log(res)
  //       if (res.yao_type == 1) {
  //         that.setData({
  //           type: 0
  //         })
  //       } else {
  //         that.setData({
  //           type: 1
  //         })
  //       }
  //     }
  //   })
  // },

  //查询是否是团队队长
  getMyiftongyi: function() {
    var that = this
    var t_id = that.data.t_id
    a.util.request({
      'url': 'entry/wxapp/Yaoqing',
      data: {
        t_id: t_id,
        openid: wx.getStorageSync('openid'),
        op: 'ifduiz'
      },
      success: function(res) {
        console.log(res)
        if (res.data == 1) {
          that.setData({
            type: 0
          })
        } else {
          that.setData({
            type: 1
          })
        }
      }
    })
  },
});